package com.tools.app.service.impl;

import com.hm.base.android.mob.AMApplication;
import com.hm.base.android.mob.service.ActionException;
import com.hm.base.android.mob.service.impl.HttpMobService;
import com.hm.base.android.mob.service.impl.ProtocolWrap;
import com.hm.base.android.mob.util.AppInfoUtil;
import com.hm.base.android.mob.util.Des3Util;
import com.tools.app.handle.ReferrerHandler;
import com.tools.app.service.IAppHttpService;

/**
 * Created by ChenLi on 2017/12/13.
 */

public class AppHttpService extends HttpMobService implements IAppHttpService {

    private AppProtocolFactory protocolFactory;

    public AppHttpService(AMApplication imContext, AppProtocolFactory factory) {
        super(imContext, factory);
        protocolFactory = factory;
    }

    @Override
    protected String getDefaultHostUrl() {
        return null;
    }

    @Override
    public int submitReferrer(String referrer, long time) throws ActionException {
        String sha1SingInfo = AppInfoUtil.getSha1SingInfo(imContext);
        referrer = Des3Util.encrypt(referrer, sha1SingInfo);

        ProtocolWrap protocolWrap = protocolFactory.submitReferrer(referrer, time);
        byte[] result = requestServiceResource(protocolWrap);
        ReferrerHandler handler = new ReferrerHandler();
        handler.parserJson(result);

        return handler.getCustomCodeMark();
    }

}
